package io.shallwe._admin.basedata.hangerframe;

import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.kit.Ret;
import io.shallwe.common.controller.BaseController;
import io.shallwe.common.model.Account;
import io.shallwe.common.model.HangerFrameMiddle;

/**
 * 挂框号、电泳框号绑定
 * @author : 王小伟
 * @date : 2019-07-18 14:46:30
 */
public class HangerFrameController extends BaseController {

    @Inject
    HangerFrameService service;

    /**
     * 视图页面
     */
    public void index(){
        render("rackFrame.html");
    }

    /**
     * 分页查询
     */
    public void list(){
        Integer offset = getParaToInt("offset", 1);
        Integer pageSize = getParaToInt("pageSize", 10);
        String hangerNo=get("hangerNo");
        String frameNo=get("frameNo");
        renderJson(service.paginate(offset, pageSize, hangerNo, frameNo));
    }

    /**
     * 新增页面
     */
    public void add(){
        render("add_edit.html");
    }

    /**
     * 保存新增内容
     */
    @Before(HangerFrameValidator.class)
    public void save(){
        HangerFrameMiddle middle = getBean(HangerFrameMiddle.class, "middle",true);
        Ret ret = service.save(middle);
        renderJson(ret);
    }

    /**
     * 编辑页面
     */
    public void edit(){
        Integer id = getInt("id");
        HangerFrameMiddle middle = service.findById(id);
        set("middle",middle);
        render("add_edit.html");
    }

    /**
     * 保持编辑内容
     */
    @Before(HangerFrameValidator.class)
    public void update(){
        HangerFrameMiddle middle = getBean(HangerFrameMiddle.class, "middle",true);
        Account loginAccount = getLoginAccount();
        middle.setChangeBy(loginAccount.getId());
        Ret ret = service.update(middle);
        renderJson(ret);
    }

    /**
     * 删除
     */
    public void delete(){
        String id = get("id");
        Ret ret = service.delete(id);
        renderJson(ret);
    }
}
